package com.xinsoft.controller.basic;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinsoft.aop.ano.SysLog;
import com.xinsoft.common.BusinessType;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysCountConfigParam;
import com.xinsoft.entity.po.SysCountConfig;
import com.xinsoft.service.SysCountConfigService;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SysCountConfigController
 * @Description 统计配置控制层
 * @Author hsm
 * @Date 2023年11月24日10:07:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/count/config")
@Api(value = "SysCountConfigController", tags = {"统计配置"})
public class SysCountConfigController {
	@Autowired
	private SysCountConfigService configService;


	/**
	 * @Description 统计配置-新增
	 **/
	@SysLog(title = "统计配置-新增", businessType = BusinessType.INSERT)
	@ApiOperation("新增")
	@PostMapping("/add")
	public Response<?> add(@RequestBody SysCountConfig config) {
		// 参数校验
		ValidatorUtils.validateEntity(config);
		return Response.succeed(configService.save(config));
	}

	/**
	 * @Description 更新
	 **/
	@ApiOperation("更新")
	@SysLog(title = "统计配置-编辑", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	public Response<?> edit(@RequestBody SysCountConfig config) {
		// 参数校验
		ValidatorUtils.validateEntity(config);
		return Response.succeed(configService.updateById(config));
	}

	/**
	 * @Description 获取详情
	 **/
	@ApiOperation("获取详情")
	@GetMapping("/detail")
	public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
		return Response.succeed(configService.getById(id));
	}

	/**
	 * @Description 删除
	 * @params   ids
	 **/
	@ApiOperation("删除")
	@SysLog(title = "统计配置-删除", businessType = BusinessType.DELETE)
	@PostMapping("/del")
	public Response<?> del(@RequestBody List<Integer> ids) {
		configService.removeByIds(ids);
		return Response.succeed();
	}

	/**
	 * @Description 统计配置分页
	 **/
	@PostMapping("/pageList")
	public Response<?> pageList(@Valid @RequestBody SysCountConfigParam param) {
		return Response.succeed(configService.findPageListByParam(param));
	}
}
